<template>
    <div>
        <template>
             <div class="align-right">
              <el-form :inline="true" :model="listQuery">
                  <div class="pull-right">
                    <el-form-item label="状态：">
                            <el-select v-model="listQuery.state" placeholder="请选择状态">
                                <el-option
                                v-for="item in status"
                                :key="item.codeKey"
                                :label="item.codeValue"
                                :value="item.codeKey">
                                </el-option>
                            </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-input
                            placeholder="请输入专题名称关键词"
                            clearable
                            v-model="listQuery.title">
                        </el-input>
                    </el-form-item>
                    <el-form-item>
                      <el-button type="primary" @click="handleSearch" icon="el-icon-search" >搜索</el-button>
                    </el-form-item>
                  </div>
                  <div>
                    <el-button @click="addTopic">新建专题</el-button>
                  </div>
              </el-form>
            </div>
             <el-table
                v-loading="loading"
                class="mb20"
                ref="topic_table"
                :data="topic_tables"
                row-key="id"
                border
                highlight-current-row
                @selection-change="handleSelectionChange"
                style="width: 100%">
                <el-table-column
                    type="selection"
                    width="55">
                </el-table-column>
               <el-table-column align="center" label="序号" min-width ="70" >
                    <template slot-scope="scope">
                        <span>{{ scope.$index+1 }}</span>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="专题名称" min-width ="450" >
                    <template slot-scope="scope">
                        <span>{{ scope.row.title }}</span>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="置顶权重" min-width ="80" >
                    <template slot-scope="scope">
                        <span>{{ scope.row.topNum }}</span>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="发布者" min-width ="100" >
                    <template slot-scope="scope">
                        <span>{{ scope.row.promulgator }}</span>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="发布时间" min-width ="155" >
                    <template slot-scope="scope">
                        <span>{{ scope.row.publishDt }}</span>
                    </template>
                </el-table-column>
                
                <el-table-column align="center" label="状态" min-width ="80" >
                    <template slot-scope="scope">
                        <span>{{ scope.row.stateNm }}</span>
                    </template>
                </el-table-column>
            
                <el-table-column align="center" label="操作" width ="270" >
                    <template slot-scope="scope">
                        <el-button type="text"  @click="edit(scope)">编辑</el-button>
                        <el-button type="text"  @click="remove(scope)">删除</el-button>
                        <!-- <el-button type="text" @click="push(scope)">推送</el-button>
                        <span>|</span>
                        <el-button type="text" @click="setFreeRead(scope)">设置试读</el-button>
                        <span>|</span>
                        <el-button type="text" @click="comment(scope)">评论</el-button> -->
                         <el-button type="text" v-clipboard:copy='scope.row.id' v-clipboard:success='clipboardSuccess'>复制ID</el-button>
                    </template>
                </el-table-column>
             </el-table>
              <el-col :span="24" style="margin-top:10px" v-if="topic_tables.length>0">
                <el-button size="small" @click="bathRemove">批量删除</el-button>
            </el-col>
             <el-col :span="24" class="pagination-warp" v-if="topic_tables.length>0">
                <div class="text-center">
                    <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="listQuery.currentPage"
                        :page-sizes="[10, 20, 30, 50]"
                        :page-size="listQuery.size"
                        layout="total, sizes, prev, pager, next ,jumper"
                        :total="total">
                    </el-pagination>
                </div>
            </el-col>
        </template>
    </div>
</template>
<script>
import clip from '@/utils/clipboard' // use clipboard directly
import clipboard from '@/directive/clipboard/index.js' // use clipboard by v-directive
import { getDetail } from '@/api/sys/detail'
import {selectList} from '@/api/topic/topic'

export default {
     directives: {
        clipboard
    },
    data() {
        return {
            loading:false,
            topic_tables:[],
            status: [],
            selections:[],
            listQuery: {
                currentPage: 1,
                size: 10,
                state: '',
                title: undefined
            },
        }
    },
    created() {
        this.getList()
        this.getStatus()
    },
    methods:{
        getList(){
            this.loading = true
            const params = this.listQuery
            selectList(params).then(response => {
                this.topic_tables = response.data.records
                this.total = response.data.total
                this.loading = false
            })
        },
        getStatus(){
            const param = {masterKey:"CONT_STAT"}
            getDetail(param).then(response => {
                if(response.code === 0){
                    this.status = response.data
                    this.status.unshift({id:-1,codeKey:'',codeValue:'全部'})
                }
            })
        },
         clipboardSuccess() {
            this.$message({
                message: '复制成功',
                type: 'success',
                duration: 1500
            })
        },
        handleSearch(){
            this.listQuery.currentPage = 1
            this.getList()
        },
        handleSizeChange(val) {
            this.listQuery.currentPage = 1
            this.listQuery.size = val
            this.getList()
        },
        handleCurrentChange(val) {
            this.listQuery.currentPage = val
            this.getList()
        },
        handleSelectionChange(values){
            this.selections = []
            values.forEach(v => {
                let data = {id:v.id}
                this.selections.push(data)
            })
        },
        addTopic(){
            this.$router.push({"path":"/topic/addTopic","query":{router:'新建专题'}})
        }
    }
}
</script>

